define(
    ["PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/slidebar", "PDUtilDir/inputSelect", "PDUtilDir/fileupload/multiFileUpload", "Date", "DateCN", "css!DateCss"],
    function (Util, Tool, Slidebar, inputSelect, MFU) {
        function reserveSupportInit($scope, $compile) {
            return new reserveSupport($scope, $compile);
        };

        function reserveSupport($scope, $compile) {
            this.$scope = $scope;
            this.$compile = $compile;
        };
        reserveSupport.fn = reserveSupport.prototype;

        reserveSupport.fn.init = function (id) {
            this.entity = {
                provideDeptId: id,
                cars: new Array()
            };
            this.bind = {};
            this.cache = {
                startPlaceCity: new Array(),
                endPlaceCity: new Array(),
                startPlaceZone: new Array(),
                endPlaceZone: new Array(),
            }
        };

        reserveSupport.fn.digest = function () {
            this.$scope.$digest();
        };

        reserveSupport.fn.run = function (id) {
            var _this = this;
            _this.init(id);

            this.slidebars = Slidebar({
                size: 'lg',
                url: getServer()
                + "/static/app/fleet/cteamInfos/views/reserve.html",
//					close : true,
                $scope: this.$scope,
                $compile: this.$compile,
                afterLoad: function ($Panel) {
                    _this.initialization();
                }
            });
        };
        reserveSupport.fn.initialization = function () {
            this.baseInit();
        };
        reserveSupport.fn.baseInit = function () {
            var _this = this;
            //车辆类型
            inputSelect.dropCache();
            inputSelect({
                id: "typeName",
                key: {
                    id: "dictCode",
                    name: "dictName",
                    data: "data",
                },
                data: _this.$scope.cache.type,
                simpleData: true,
                searchAble: false,
                callback: function (id) {
                    _this.bind.carType = id[0];
                    _this.$scope.reserveForm.carType.$setViewValue(_this.bind.carType);
                }
            });
            //用车日期
            $("#useDate").datetimepicker({
                //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
                language : "cn",
                //输出格式化
                format : 'yyyy-mm-dd hh:ii:ss',
                //直接选择‘今天’
                todayBtn : true,
                //设置最精确的时间选择视图
                minView : 'hour',
                //高亮当天日期
                todayHighlight : true,
                //显示“上午”“下午”
                showMeridian : true,
                //选择完毕后自动关闭
                autoclose : true
            });
            //还车日期
            $("#returnDate").datetimepicker({
                //设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
                language : "cn",
                //输出格式化
                format : 'yyyy-mm-dd hh:ii:ss',
                //直接选择‘今天’
                todayBtn : true,
                //设置最精确的时间选择视图
                minView : 'hour',
                //高亮当天日期
                todayHighlight : true,
                //显示“上午”“下午”
                showMeridian : true,
                //选择完毕后自动关闭
                autoclose : true
            });

            /*//出发省
            inputSelect.dropCache();
            inputSelect({
                id: "_startPlaceProvince",
                key: {
                    id: "dictCode",
                    name: "dictName",
                    data: "data",
                },
                data: _this.$scope.cache.provinces,
                simpleData: true,
                searchAble: false,
                callback: function (id) {
                    _this.entity.startPlaceProvince = id[0];
                    _this.$scope.reserveForm.startPlaceProvince.$setViewValue(_this.entity.startPlaceProvince);
                    _this.getCity('start', _this.entity.startPlaceProvince);
                }
            });
            //目的省
            inputSelect.dropCache();
            inputSelect({
                id: "_endPlaceProvince",
                key: {
                    id: "dictCode",
                    name: "dictName",
                    data: "data",
                },
                data: _this.$scope.cache.provinces,
                simpleData: true,
                searchAble: false,
                callback: function (id) {
                    _this.entity.endPlaceProvince = id[0];
                    _this.$scope.reserveForm.endPlaceProvince.$setViewValue(_this.entity.endPlaceProvince);
                    _this.getCity('end', _this.entity.endPlaceProvince);
                }
            });*/
        };
        //获取城市信息
        reserveSupport.fn.getCity = function (type, pcode) {
            var _this = this;
            $.ajax({
                url: getServer() + "/flea/hclv/getCity.htmls",
                data: {
                    'pcode': pcode
                },
                success: function (data) {
                    if (data.status != 200) {
                        return;
                    }
                    if (type == "start") {
                        _this.cache.startPlaceCity = data.data;
                        _this.init_startPlaceCity();
                    } else {
                        _this.cache.endPlaceCity = data.data;
                        _this.init_endPlaceCity();
                    }
                }
            });
        };
        //获取城市信息
        reserveSupport.fn.getZone = function (type, pcode) {
            var _this = this;
            $.ajax({
                url: getServer() + "/flea/hclv/getZone.htmls",
                data: {
                    'pcode': pcode
                },
                success: function (data) {
                    if (data.status != 200) {
                        return;
                    }
                    if (type == "start") {
                        _this.cache.startPlaceZone = data.data;
                        _this.init_startPlaceZone();
                    } else {
                        _this.cache.endPlaceZone = data.data;
                        _this.init_endPlaceZone();
                    }
                }
            });
        };
        //出发城市下拉框初始化
        reserveSupport.fn.init_startPlaceCity = function () {
            // 初始化下拉框
            var _this = this;
            inputSelect.dropCache();
            inputSelect({
                id: "_startPlaceCity",
                key: {
                    id: "dictCode",
                    name: "dictName",
                    data: "data",
                },
                data: _this.cache.startPlaceCity,
                simpleData: true,
                // 启用文本搜索
                // initData:[initProvice],
                searchAble: false,
                callback: function (id) {
                    _this.entity.startPlaceCity = id[0];
                    _this.$scope.reserveForm.startPlaceCity.$setViewValue(_this.entity.startPlaceCity);
                    _this.getZone('start', _this.entity.startPlaceCity);
                }
            });
        };
        //目的城市下拉框初始化
        reserveSupport.fn.init_endPlaceCity = function () {
            // 初始化下拉框
            var _this = this;
            inputSelect.dropCache();
            inputSelect({
                id: "_endPlaceCity",
                key: {
                    id: "dictCode",
                    name: "dictName",
                    data: "data",
                },
                data: _this.cache.endPlaceCity,
                simpleData: true,
                // 启用文本搜索
                // initData:[initProvice],
                searchAble: false,
                callback: function (id) {
                    _this.entity.endPlaceCity = id[0];
                    _this.$scope.reserveForm.endPlaceCity.$setViewValue(_this.entity.endPlaceCity);
                    _this.getZone('end', _this.entity.endPlaceCity);
                }
            });
        }
        //出发县下拉框初始化
        reserveSupport.fn.init_startPlaceZone = function () {
            // 初始化下拉框
            var _this = this;
            inputSelect.dropCache();
            inputSelect({
                id: "_startPlaceZone",
                key: {
                    id: "dictCode",
                    name: "dictName",
                    data: "data",
                },
                data: _this.cache.startPlaceZone,
                simpleData: true,
                searchAble: false,
                callback: function (id) {
                    _this.entity.startPlaceZone = id[0];
                    _this.$scope.reserveForm.startPlaceZone.$setViewValue(_this.entity.startPlaceZone);
                }
            });
        };
        //目的县下拉框初始化
        reserveSupport.fn.init_endPlaceZone = function () {
            // 初始化下拉框
            var _this = this;
            inputSelect.dropCache();
            inputSelect({
                id: "_endPlaceZone",
                key: {
                    id: "dictCode",
                    name: "dictName",
                    data: "data",
                },
                data: _this.cache.endPlaceZone,
                simpleData: true,
                searchAble: false,
                callback: function (id) {
                    _this.entity.endPlaceZone = id[0];
                    _this.$scope.reserveForm.endPlaceZone.$setViewValue(_this.entity.endPlaceZone);
                }
            });
        }
        reserveSupport.fn.add = function () {
            this.entity.cars.push(this.bind);
            this.bind = {};
            this.$scope.reserveForm.type.$setViewValue(this.bind.type);
        };

        reserveSupport.fn.save = function () {
            var _this = this, files = new Array();
            // $.each(_this.bind.images, function (index, row) {
            //     files.push({
            //         resouceId: row.resouceId,
            //         path: row.path
            //     });
            // });
            $.ajax({
                url: getServer() + "/flea/hclv/car/reserve/add.htmls",
                data: {
                    'model': JSON.stringify(_this.entity)
                },
                success: function (data) {
                    if (data.status != 200) {
                        return;
                    }
                    _this.$scope.grid.refresh();
                    Util.alert(data.message);
                    _this.slidebars.close();
                }
            });
        };
        return reserveSupportInit;
    });